package Test2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test2 {
    public static void main(String[] args) {
        //定义list集合
        List<Woker> list = new ArrayList<Woker>();
        list.add(new Woker("凤姐",18,20000));
        list.add(new Woker("欧阳锋",60,8000));
        list.add(new Woker("刘德华",40,30000));
        System.out.println(list.toString());
        //在"欧阳峰"之前插入一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300
        list.add(1,new Woker("张柏芝",35,3300));
        System.out.println(list);
        //删除"刘德华"的信息
        list.remove(3);
        System.out.println(list);
        //利用for 循环遍历，打印List 中所有员工的信息
        for (Woker x: list ) {
            System.out.println(x);
        }
        //利用迭代遍历，对List 中所有的员工调用work 方法
        Iterator it = list.iterator();
        while (it.hasNext()){
            Woker woker = (Woker) it.next();
            woker.work();
        }
        //为Worker类重写equals 方法，当姓名、年龄、工资全部相等时候才返回true
        Woker test1 = new Woker("凤姐",18,20000);
        Woker test2 = new Woker("凤姐",18,20000);
        Woker test3 = new Woker("凤哥",18,20000);
        Woker test4 = new Woker("凤姐",19,20000);
        Woker test5 = new Woker("凤姐",18,30000);
        //完全相等
        System.out.println(test1.equals(test2));
        //姓名不相等
        System.out.println(test1.equals(test3));
        //年龄不相等
        System.out.println(test1.equals(test4));
        //工资不相等
        System.out.println(test1.equals(test5));
    }
}
